<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="报修单号" prop="reportId">
        <el-input
          v-model="queryParams.reportId"
          placeholder="请输入报修单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备编码" prop="deviceCode">
        <el-input
          v-model="queryParams.deviceCode"
          placeholder="请输入设备编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报修人" prop="reportName">
        <el-input
          v-model="queryParams.reportName"
          placeholder="请输入报修人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系方式" prop="reportPhone">
        <el-input
          v-model="queryParams.reportPhone"
          placeholder="请输入联系方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发生时间" prop="occurrenceTime">
        <el-input
          v-model="queryParams.occurrenceTime"
          placeholder="请输入发生时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否停机" prop="isShutDown">
        <el-input
          v-model="queryParams.isShutDown"
          placeholder="请输入是否停机"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主修人" prop="major">
        <el-input
          v-model="queryParams.major"
          placeholder="请输入主修人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="辅助维修人" prop="fzMajor">
        <el-input
          v-model="queryParams.fzMajor"
          placeholder="请输入辅助维修人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="配件单号" prop="partsNo">
        <el-input
          v-model="queryParams.partsNo"
          placeholder="请输入配件单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['device:deviceFailureInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['device:deviceFailureInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['device:deviceFailureInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['device:deviceFailureInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="deviceFailureInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="公司名称" align="center" prop="factoryName" />
      <el-table-column label="公司代码" align="center" prop="factoryCode" />
      <el-table-column label="报修单号" align="center" prop="reportId" />
      <el-table-column label="设备编码" align="center" prop="deviceCode" />
      <el-table-column label="报修人" align="center" prop="reportName" />
      <el-table-column label="联系方式" align="center" prop="reportPhone" />
      <el-table-column label="发生时间" align="center" prop="occurrenceTime" />
      <el-table-column label="是否停机" align="center" prop="isShutDown" />
      <el-table-column label="停机时长" align="center" prop="shutdownDuration" />
      <el-table-column label="故障描述" align="center" prop="faultDescription" />
      <el-table-column label="故障图片" align="center" prop="faultImg" />
      <el-table-column label="报修语音" align="center" prop="reportVoice" />
      <el-table-column label="紧急程度" align="center" prop="faultUrgency" />
      <el-table-column label="故障等级" align="center" prop="faultLevel" />
      <el-table-column label="故障类别" align="center" prop="faultType" />
      <el-table-column label="处理进度" align="center" prop="faultProgress" />
      <el-table-column label="维修单位代码" align="center" prop="repairComCode" />
      <el-table-column label="维修单位名称" align="center" prop="repairComName" />
      <el-table-column label="维修班组" align="center" prop="repairTeam" />
      <el-table-column label="主修人" align="center" prop="major" />
      <el-table-column label="主修人id" align="center" prop="majorId" />
      <el-table-column label="辅助维修人" align="center" prop="fzMajor" />
      <el-table-column label="辅助维修人id" align="center" prop="fzMajoId" />
      <el-table-column label="开始时间" align="center" prop="startTime" />
      <el-table-column label="结束时间" align="center" prop="endTime" />
      <el-table-column label="维修用时" align="center" prop="repairTimeuse" />
      <el-table-column label="维修费用" align="center" prop="repairCosts" />
      <el-table-column label="工时定额" align="center" prop="timQuota" />
      <el-table-column label="维修类别" align="center" prop="repairType" />
      <el-table-column label="维修级别" align="center" prop="repairLevel" />
      <el-table-column label="维修描述" align="center" prop="repairDescription" />
      <el-table-column label="维修图片" align="center" prop="repairImg" />
      <el-table-column label="配件单号" align="center" prop="partsNo" />
      <el-table-column label="配件费用" align="center" prop="partsCosts" />
      <el-table-column label="维修结果" align="center" prop="repairResult" />
      <el-table-column label="维修评分" align="center" prop="repairScore" />
      <el-table-column label="评价" align="center" prop="repairEvaluate" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['device:deviceFailureInfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['device:deviceFailureInfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改设备故障列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="公司名称" prop="factoryName">
          <el-input v-model="form.factoryName" placeholder="请输入公司名称" />
        </el-form-item>
        <el-form-item label="公司代码" prop="factoryCode">
          <el-input v-model="form.factoryCode" placeholder="请输入公司代码" />
        </el-form-item>
        <el-form-item label="报修单号" prop="reportId">
          <el-input v-model="form.reportId" placeholder="请输入报修单号" />
        </el-form-item>
        <el-form-item label="设备编码" prop="deviceCode">
          <el-input v-model="form.deviceCode" placeholder="请输入设备编码" />
        </el-form-item>
        <el-form-item label="报修人" prop="reportName">
          <el-input v-model="form.reportName" placeholder="请输入报修人" />
        </el-form-item>
        <el-form-item label="联系方式" prop="reportPhone">
          <el-input v-model="form.reportPhone" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="发生时间" prop="occurrenceTime">
          <el-input v-model="form.occurrenceTime" placeholder="请输入发生时间" />
        </el-form-item>
        <el-form-item label="是否停机" prop="isShutDown">
          <el-input v-model="form.isShutDown" placeholder="请输入是否停机" />
        </el-form-item>
        <el-form-item label="停机时长" prop="shutdownDuration">
          <el-input v-model="form.shutdownDuration" placeholder="请输入停机时长" />
        </el-form-item>
        <el-form-item label="故障描述" prop="faultDescription">
          <el-input v-model="form.faultDescription" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="故障图片" prop="faultImg">
          <el-input v-model="form.faultImg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="报修语音" prop="reportVoice">
          <el-input v-model="form.reportVoice" placeholder="请输入报修语音" />
        </el-form-item>
        <el-form-item label="紧急程度" prop="faultUrgency">
          <el-input v-model="form.faultUrgency" placeholder="请输入紧急程度" />
        </el-form-item>
        <el-form-item label="故障等级" prop="faultLevel">
          <el-input v-model="form.faultLevel" placeholder="请输入故障等级" />
        </el-form-item>
        <el-form-item label="处理进度 0-待接单1-待执行2-维修中3-待评价4-完成5-驳回" prop="faultProgress">
          <el-input v-model="form.faultProgress" placeholder="请输入处理进度 0-待接单1-待执行2-维修中3-待评价4-完成5-驳回" />
        </el-form-item>
        <el-form-item label="维修单位代码" prop="repairComCode">
          <el-input v-model="form.repairComCode" placeholder="请输入维修单位代码" />
        </el-form-item>
        <el-form-item label="维修单位名称" prop="repairComName">
          <el-input v-model="form.repairComName" placeholder="请输入维修单位名称" />
        </el-form-item>
        <el-form-item label="维修班组" prop="repairTeam">
          <el-input v-model="form.repairTeam" placeholder="请输入维修班组" />
        </el-form-item>
        <el-form-item label="主修人" prop="major">
          <el-input v-model="form.major" placeholder="请输入主修人" />
        </el-form-item>
        <el-form-item label="主修人id" prop="majorId">
          <el-input v-model="form.majorId" placeholder="请输入主修人id" />
        </el-form-item>
        <el-form-item label="辅助维修人" prop="fzMajor">
          <el-input v-model="form.fzMajor" placeholder="请输入辅助维修人" />
        </el-form-item>
        <el-form-item label="辅助维修人id" prop="fzMajoId">
          <el-input v-model="form.fzMajoId" placeholder="请输入辅助维修人id" />
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime">
          <el-input v-model="form.startTime" placeholder="请输入开始时间" />
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-input v-model="form.endTime" placeholder="请输入结束时间" />
        </el-form-item>
        <el-form-item label="维修用时" prop="repairTimeuse">
          <el-input v-model="form.repairTimeuse" placeholder="请输入维修用时" />
        </el-form-item>
        <el-form-item label="维修费用" prop="repairCosts">
          <el-input v-model="form.repairCosts" placeholder="请输入维修费用" />
        </el-form-item>
        <el-form-item label="工时定额" prop="timQuota">
          <el-input v-model="form.timQuota" placeholder="请输入工时定额" />
        </el-form-item>
        <el-form-item label="维修级别" prop="repairLevel">
          <el-input v-model="form.repairLevel" placeholder="请输入维修级别" />
        </el-form-item>
        <el-form-item label="维修描述" prop="repairDescription">
          <el-input v-model="form.repairDescription" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="维修图片" prop="repairImg">
          <el-input v-model="form.repairImg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="配件单号" prop="partsNo">
          <el-input v-model="form.partsNo" placeholder="请输入配件单号" />
        </el-form-item>
        <el-form-item label="配件费用" prop="partsCosts">
          <el-input v-model="form.partsCosts" placeholder="请输入配件费用" />
        </el-form-item>
        <el-form-item label="维修结果" prop="repairResult">
          <el-input v-model="form.repairResult" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="维修评分0-1-2-3-4-5" prop="repairScore">
          <el-input v-model="form.repairScore" placeholder="请输入维修评分0-1-2-3-4-5" />
        </el-form-item>
        <el-form-item label="评价" prop="repairEvaluate">
          <el-input v-model="form.repairEvaluate" placeholder="请输入评价" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDeviceFailureInfo, getDeviceFailureInfo, delDeviceFailureInfo, addDeviceFailureInfo, updateDeviceFailureInfo } from "@/api/device/deviceFailureInfo";

export default {
  name: "DeviceFailureInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备故障列表表格数据
      deviceFailureInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        reportId: null,
        deviceCode: null,
        reportName: null,
        reportPhone: null,
        occurrenceTime: null,
        isShutDown: null,
        major: null,
        fzMajor: null,
        partsNo: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询设备故障列表列表 */
    getList() {
      this.loading = true;
      listDeviceFailureInfo(this.queryParams).then(response => {
        this.deviceFailureInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        factoryName: null,
        factoryCode: null,
        reportId: null,
        deviceCode: null,
        reportName: null,
        reportPhone: null,
        occurrenceTime: null,
        isShutDown: null,
        shutdownDuration: null,
        faultDescription: null,
        faultImg: null,
        reportVoice: null,
        faultUrgency: null,
        faultLevel: null,
        faultType: null,
        faultProgress: null,
        repairComCode: null,
        repairComName: null,
        repairTeam: null,
        major: null,
        majorId: null,
        fzMajor: null,
        fzMajoId: null,
        startTime: null,
        endTime: null,
        repairTimeuse: null,
        repairCosts: null,
        timQuota: null,
        repairType: null,
        repairLevel: null,
        repairDescription: null,
        repairImg: null,
        partsNo: null,
        partsCosts: null,
        repairResult: null,
        repairScore: null,
        repairEvaluate: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加设备故障列表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDeviceFailureInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改设备故障列表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDeviceFailureInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDeviceFailureInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除设备故障列表编号为"' + ids + '"的数据项？').then(function() {
        return delDeviceFailureInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('device/deviceFailureInfo/export', {
        ...this.queryParams
      }, `deviceFailureInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
